/* 根页 - 包含了根级路由 */
import React from 'react';
import { Router, BrowserRouter, Route, Switch, Redirect} from 'react-router-dom';
import P from 'prop-types';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
// import createHistory from 'history/createBrowserHistory';
import createHistory from 'history/createHashHistory';

/* 下面是代码分割异步加载的例子 */
// import Bundle from '../../a_component/bundle';
// import  lazeBsDemo from 'bundle-loader?lazy!../bsdemo';
// const BsDemo = (props) => (
//     <Bundle load={lazeBsDemo}>
//         {(BsDemo) => <BsDemo {...props} />}
//     </Bundle>
// );
/* 上面是代码分割异步加载的例子 */

/* 下面是代码不分割的用法 */
import BsDemo from '../home';


const history = createHistory();
class RootContainer extends React.Component {
  constructor(props) {
    super(props);
  }

  /* 权限控制 */
  onEnter(Component, props) {
    console.log('权限控制：', props);
    // 例子：如果没有登录，直接跳转至login页
    // if (sessionStorage.getItem('userInfo')) {
    //   return <Component {...props} />;
    // } else {
    //   return <Redirect to='/login' />;
    // }
    return <Component {...props}/>;
  }

  render() {
    return ([
      <Router history={history} key="history">
            <div className="boss">
                  {/*<Redirect exact from='/' to='/bs' />*/}
                  <Route path="/" render={(props) => this.onEnter(BsDemo, props)} />
            </div>
      </Router>,

    ]);
  }
}

// ==================
// PropTypes
// ==================

RootContainer.propTypes = {
  dispatch: P.func,
  children: P.any,
};

// ==================
// Export
// ==================

export default connect(
  (state) => ({
  }),
  (dispatch) => ({
      actions: bindActionCreators({}, dispatch),
  })
)(RootContainer);


